package com.t2b.thaicalendar.view;

import android.app.Activity;
import android.app.DialogFragment;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.t2b.thaicalendar.R;
import com.t2b.thaicalendar.dto.Days;
import com.t2b.thaicalendar.holiday.Holiday;

/**
 * Created by j1tth4 on 7/11/14 AD.
 */
public class DayDetailPopup extends PopupWindow{

    private Context mContext;

    private Days mDay;

    private TextView mTvToday;
    private TextView mTvBuddha;
    private TextView mTvHoliday;
    private ImageView mImvBuddha;

    public DayDetailPopup(Context context, Days day) {
        super(context);
        mContext = context;
        mDay = day;
        LayoutInflater inflater = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View content = inflater.inflate(R.layout.day_detail, null);
        setContentView(content);
        mTvToday = (TextView) content.findViewById(R.id.tvToday);
        mTvBuddha = (TextView) content.findViewById(R.id.tvBuddha);
        mTvHoliday = (TextView) content.findViewById(R.id.tvHoliday);
        mImvBuddha = (ImageView) content.findViewById(R.id.imgBuddha);
        setOutsideTouchable(true);
//        setBackgroundDrawable(mContext.getResources()
//                        .getDrawable(R.drawable.default_background));
        setWidth(240);
        setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

        setDayDetail();
    }

    private void setDayDetail(){
        mTvToday.setText(mDay.data.get(Days.DAY).toString());
        Object holiday = mDay.data.get(Days.HOLIDAY);
        Object waxing = mDay.data.get(Days.WAXING);
        if(waxing != null) {
            mTvBuddha.setText(
                    ((waxing.equals("WX") ?
                            mContext.getString(R.string.buddhaWaxing) :
                            mContext.getString(R.string.buddhaWaning)) + " "
                            + mDay.data.get(Days.WAXING_DAY) + " " +
                            mContext.getString(R.string.buddhaDayPrefix)) + " "
                            + mContext.getString(R.string.buddhaMonthPrefix) + " "
                            + mDay.data.get(Days.WAXING_MONTH_2)
            );
            //WanPhra
            if ((Boolean) mDay.data.get(Days.WAXING_WANPRA)) {
                mImvBuddha.setVisibility(View.VISIBLE);
            }else{
                mImvBuddha.setVisibility(View.GONE);
            }
        }
        if(holiday != null){
            mTvHoliday.setText(holiday.toString());
            mTvToday.setTextColor(Color.RED);
        }else{
            mTvHoliday.setText(null);
        }
    }
}
